<?php
/* @var $this PenerimaanTamuController */
/* @var $model PenerimaanTamu */

$this->breadcrumbs=array(
	'Penerimaan Tamu'=>array('admin'),
	'Create',
);

?>

<?php $this->beginWidget('ext.widgets.XPanel', array('width'=>900, 'height'=>130, 'title'=> 'Penerimaan Tamu')); ?>

<!-- form start -->
<div class="form">
	<?php $form = $this->beginWidget('CActiveForm', 
                array(
                    'id' => 'penerimaan-tamu-form',
                    'enableAjaxValidation'=>true,
                    'enableClientValidation'=>true,
                    'clientOptions'=>array(
                            'validateOnSubmit'=>true,
                    ),
                    'htmlOptions'=>array(
                               'onsubmit'=>"console.log(value);return false;",/* Disable normal form submit */
                               'onkeypress'=>" if(event.keyCode == 13){ send(); } " /* Do ajax call when user presses enter key */
                             )
                    )
                );?>
	<fieldset>
		<legend>Data Tamu</legend>
		<table>
			<tr>
				<td width="150"><?php echo $form->label($Tamu, 'nama');?></td>
				<td width="200">
					<?php 
					echo $form->hiddenField($Tamu, 'id_tamu');
                                        $this->widget('ext.jui.CustomAutoComplete',
                                                    array(
                                                    'model'=>$Tamu,
                                                    'attribute'=>'nama',
                                                    'source'=>$this->createUrl('Tamu/autocomplete', array('by'=>'nama')),
                                                    'htmlOptions'=>array('placeholder'=>'Nama Tamu'),
                                                    'methodChain'=>'.data( "autocomplete" )._renderItem = function( ul, item ) {
                                                        return $( "<li></li>" )
                                                            .data( "item.autocomplete", item )
                                                            .append("<a><img src="+item.foto+" height=40px  style=float:left>"+ item.nama +" ("+item.Instansi+")<br/><span style=font-size:10px>" + item.no_identitas +  "("+ item.jenis_identitas +")</span></a>")
                                                            .appendTo( ul );
                                                    };',
                                                    'options'=>
                                                        array(
                                                            'mustMatch'=> TRUE,
                                                            'showAnim'=>'fold',
                                                            'select'=>"js:function(rollback, ui) {
                                                                $('#Tamu_nama').val(ui.item.nama);
                                                                 $('#Tamu_id_tamu').val(ui.item.id);
                                                                 $('#Tamu_no_identitas').val(ui.item.no_identitas);
                                                                 $('#Tamu_jenis_identitas').val(ui.item.jenis_identitas);
                                                                 $('#Tamu_no_telp').val(ui.item.no_telp);
                                                                 $('#Instansi_nama').val(ui.item.Instansi);
                                                                 $('#Instansi_id_instansi').val(ui.item.id_instansi);
                                                                }"
                                                                ),
                                                    'cssFile'=>false,
                                                    ));
                                                    
					echo $form->error($Tamu, 'nama');
                                        
					?>
				</td>
				<td>&nbsp;</td>
				<td width="150"><?php echo $form->label($Tamu, 'no_telp');?></td>
				<td width="200">
					<?php 
					echo $form->textField($Tamu, 'no_telp');
					echo $form->error($Tamu, 'no_telp');
					?>
				</td>
				<td rowspan="5" width="300" >
                                        
                                        <!-- modal start-->
                                        <div id="modal" >
                                            
                                            <?php
                                                $completionHandler = "
                                                    if (msg != 'ERROR') {
                                                        
                                                        $('#modal').hide();
                                                        // reset camera for another shot
                                                        //webcam.reset();
                                                        //setTimeout(function(){window.location = 'index.php?r=user/index';},3000);
                                                    }
                                                    else alert('PHP Error: ' + msg);
                                                    ";

                                                $this->widget('application.extensions.jpegcam.EJpegcam', array(
                                                        'apiUrl' => Yii::app()->createUrl('PenerimaanTamu/jpegcam.saveJpg'),
                                                        'shutterSound' => true,
                                                        'jpegQuality' => 100,
                                                        //'camWidth' => '210',
                                                        //'camHeight' => '150',
                                                        'serverWidth' => '220',
                                                        'serverHeight' => '140',
                                                        'stealth' => true,
                                                        'buttons' => array(
                                                            //'configure' => 'Configure',
                                                            //'takesnapshot' => 'Snap',
                                                            //'freeze' => 'Capture',
                                                            //'upload' => 'Upload',
                                                            //'reset' => 'Reset'
                                                        ),
                                                        'onBeforeSnap' => '',
                                                        'completionHandler' => $completionHandler
                                                    ));
                                                
                                                ?>
                                                
                                        </div>
                                        <!-- modal end -->
                                        
                                            
                                        <?php
                                            echo "<br/>";
                                                echo CHtml::button('Snap', array('id'=>'photoSnap', 'onClick'=>'snap()'));
                                                echo CHtml::button('Reset', array('id'=>'photoReset', 'onClick' =>'hide()', 'style'=>'display:none'));
                                                Yii::app()->clientScript->registerScript('script', 
                                                    "
                                                       function snap(){
                                                            webcam.freeze();
                                                            $('#photoSnap').hide();
                                                            $('#photoReset').show();
                                                       }
                                                       
                                                       function hide(){
                                                           webcam.reset()
                                                            $('#photoSnap').show();
                                                            $('#photoReset').hide();
                                                       }
                                                       
                                                         
                                                    "
                                                , CClientScript::POS_BEGIN);
                                        ?>
				</td>
			</tr>
			<tr>
				<td width="150"><?php echo $form->label($Tamu, 'no_identitas');?></td>
				<td width="500">
					<?php 
                                        $this->widget('ext.jui.CustomAutoComplete',
                                                    array(
                                                    'model'=>$Tamu,
                                                    'attribute'=>'no_identitas',
                                                    'source'=>$this->createUrl('Tamu/autocomplete', array('by'=>'no_identitas')),
                                                    'htmlOptions'=>array('placeholder'=>'No Identitas'),
                                                    'methodChain'=>'.data( "autocomplete" )._renderItem = function( ul, item ) {
                                                        return $( "<li></li>" )
                                                            .data( "item.autocomplete", item )
                                                            .append("<a>" + item.no_identitas +  "("+ item.jenis_identitas +")<br/><span style=font-size:10px>"+ item.nama +" ("+item.Instansi+")</span></a>")
                                                            .appendTo( ul );
                                                    };',
                                                    'options'=>
                                                        array(
                                                            'mustMatch'=> TRUE,
                                                            'showAnim'=>'fold',
                                                            'select'=>"js:function(rollback, ui) {
                                                                $('#Tamu_nama').val(ui.item.nama);
                                                                 $('#Tamu_id_tamu').val(ui.item.id);
                                                                 $('#Tamu_no_identitas').val(ui.item.no_identitas);
                                                                 $('#Tamu_jenis_identitas').val(ui.item.jenis_identitas);
                                                                 $('#Tamu_no_telp').val(ui.item.no_telp);
                                                                 $('#Instansi_nama').val(ui.item.Instansi);
                                                                 $('#Instansi_id_instansi').val(ui.item.id_instansi);
                                                                }"
                                                                ),
                                                    'cssFile'=>false,
                                                    ));
                                                    
					echo $form->hiddenField($Tamu, 'no_identitas');
					echo $form->error($Tamu, 'no_identitas');
					?>
				</td>
				<td>&nbsp;</td>
				<td><?php echo $form->label($PenerimaanTamu, 'jumlah_tamu');?></td>
				<td>
					<?php 
					echo $form->textField($PenerimaanTamu, 'jumlah_tamu');
					echo $form->error($PenerimaanTamu, 'jumlah_tamu');
					?>
				</td>
			</tr>
			<tr>
				<td width="150"><?php echo $form->label($Tamu, 'jenis_identitas');?></td>
				<td width="500">
					<?php 
					echo $form->textField($Tamu, 'jenis_identitas');
					echo $form->error($Tamu, 'jenis_identitas');
					?>
				</td>
				<td>&nbsp;</td>
				<td><?php echo $form->label($Tamu, 'instansi');?></td>
				<td>
					<?php 
                                                    $this->widget('zii.widgets.jui.CJuiAutoComplete',
                                                    array(
                                                    'model'=>$Instansi,
                                                    'attribute'=>'nama',
                                                    'source'=>$this->createUrl('Instansi/autocomplete'),
                                                    'htmlOptions'=>array('placeholder'=>'Instansi'),
                                                    'options'=>
                                                        array(
                                                            'autoFill'=>true,
                                                            
                                                            'showAnim'=>'fold',
                                                            'select'=>"js:function(hotel, ui) {
                                                                $('#Instansi_id_instansi').val(ui.item.id_instansi);
                                                                
                                                                }"
                                                                ),
                                                    'cssFile'=>false,
                                                    ));
                                                    echo $form->hiddenField($Instansi, 'id_instansi');
                                                    echo $form->error($Instansi, 'nama');
                                                    
                                                    
                                        Yii::app()->clientScript->registerScript('script', 
                                                    "
                                                       $('#Instansi_nama').focus(function(){
                                                            if ($(this).autocomplete('widget').is(':visible')) {
                                                                return;
                                                            }
                                                            $(this).autocomplete('search');
                                                           
                                                           $(this).val('');
                                                            $('#Instansi_id_instansi').val('');
                                                            
                                                       });

                                                       $('#Instansi_nama').focusout(function(){
                                                             if($('#Instansi_id_instansi').val()==''){
                                                             
                                                                    $(this).val('');
                                                                    $('#Instansi_id_instansi').val('');

                                                                }
                                                            
                                                       });
                                             
                                                    "
                                                , CClientScript::POS_END);
                                                    ?>
				</td>
                                
			</tr>
                        <tr><td colspan="5">&nbsp;</td></tr>
                        <tr><td colspan="5">&nbsp;</td></tr>
		</table>
	</fieldset><!--
	<fieldset> 
		<legend>Waktu/lokasi</legend>
		<table>
			<tr>
				<td width="150"><?php echo $form->label($PenerimaanTamu, 'jadwal_mulai');?></td>
				<td width="200">
                                   <?php 
                                    $this->widget(
                                                'ext.jui.EJuiDateTimePicker',
                                                array(
                                                    'model'     => $PenerimaanTamu,
                                                    'attribute' => 'jadwal_mulai',
                                                    'language'=> 'en',//default Yii::app()->language
                                                    //'mode'    => 'datetime',//'datetime' or 'time' ('datetime' default)
                                                    'options'   => array(
                                                        'dateFormat' => 'dd-mm-yy',
                                                        'timeFormat' => 'hh:mm tt',//'hh:mm tt' default
                                                    ),
                                                    'htmlOptions'=>array(
                                                        'placeholder'=>'jadwal Mulai'
                                                    )
                                                )
                                            );
                                        
					echo $form->error($PenerimaanTamu, 'jadwal_mulai');
					?>
				</td>
				<td >&nbsp;</td>
				<td width="150"><?php echo $form->label($PenerimaanTamu, 'jadwal_selesai');?></td>
				<td width="200">
					<?php 
					$this->widget(
                                                'ext.jui.EJuiDateTimePicker',
                                                array(
                                                    'model'     => $PenerimaanTamu,
                                                    'attribute' => 'jadwal_selesai',
                                                    'language'=> 'en',//default Yii::app()->language
                                                    //'mode'    => 'datetime',//'datetime' or 'time' ('datetime' default)
                                                    'options'   => array(
                                                        'dateFormat' => 'dd-mm-yy',
                                                        'timeFormat' => 'hh:mm tt',//'hh:mm tt' default
                                                    ),
                                                    'htmlOptions'=>array(
                                                        'placeholder'=>'jadwal Mulai'
                                                    )
                                                )
                                            );
					echo $form->error($PenerimaanTamu, 'jadwal_selesai');
					?>
				</td>
				<td rowspan="1" width="500">
				</td>
			</tr>
			<tr>
				<td width="150"><?php echo $form->label($Meetingroom, 'nama_ruang');?></td>
				<td width="200">
					<?php 
                                        $this->widget('zii.widgets.jui.CJuiAutoComplete',
                                        array(
                                        'model' => $Meetingroom,
                                        'attribute' => 'nama',
                                        'source' => $this->createUrl('Meetingroom/autocomplete'),
                                        'htmlOptions' => array('placeholder'=>'Nama Ruang'),
                                        'options'=>
                                            array(
                                                'showAnim'=>'fold',
                                                'select'=>"js:function(hotel, ui) {
                                                    $('#Meetingroom_id_meetingroom').val(ui.item.id);
                                                    $('#Meetingroom_kapasitas').val(ui.item.kapasitas);
                                                    $('#Meetingroom_lokasi').val(ui.item.lokasi);
                                                    }"
                                                    ),
                                        'cssFile'=>false,
                                        ));
                                        echo $form->hiddenField($Meetingroom, 'id_meetingroom');
					echo $form->error($Meetingroom, 'nama');
					?>
				</td>
				<td >&nbsp;</td>
				<td width="150"><?php echo $form->label($Meetingroom, 'lokasi');?></td>
				<td width="200">
					<?php 
					echo $form->textField($Meetingroom, 'lokasi', 
                                                array(
                                                    'placeholder' => 'lokasi',
                                                    'readonly' => 'readonly'
                                                    )
                                                );
					echo $form->error($PenerimaanTamu, 'lokasi');
					?>
				</td>
			</tr>
			<tr>
				<td width="150"><?php echo $form->label($Meetingroom, 'kapasitas');?></td>
				<td width="200">
					<?php 
					echo $form->textField($Meetingroom, 'kapasitas',
                                                array(
                                                    'placeholder' => 'lokasi',
                                                    'readonly' => 'readonly'
                                                    )
                                                );
					echo $form->error($PenerimaanTamu, 'kapasitas');
					?>
				</td>
				<td colspan="3">&nbsp;</td>
			</tr>
		</table>
	</fieldset> 
    -->
        <table>
            <tr>
                <td>
                    <fieldset>
                            <legend>Tujuan</legend>
                            <table>
                                    <tr>
                                            <td width="150"><?php echo $form->label($Pegawai, 'nama');?></td>
                                            <td width="200">
                                                    <?php 
                                                    $this->widget('ext.jui.CustomAutoComplete',
                                                    array(
                                                    'model'=>$Pegawai,
                                                    'attribute'=>'nama',
                                                    'source'=>$this->createUrl('Pegawai/autocomplete'),
                                                    'htmlOptions'=>array('placeholder'=>'Nama Personal tujuan'),
                                                    'methodChain'=>'.data( "autocomplete" )._renderItem = function( ul, item ) {
                                                        return $( "<li></li>" )
                                                            .data( "item.autocomplete", item )
                                                            .append( "<a>" + item.label +  "<br/><span style=font-size:10px>"+ item.jabatan +"</span></a>" )
                                                            .appendTo( ul );
                                                    };',
                                                    'options'=>
                                                        array(
                                                            'mustMatch'=> TRUE,
                                                            'showAnim'=>'fold',
                                                            'select'=>"js:function(hotel, ui) {
                                                                $('#Pegawai_id_pegawai').val(ui.item.id);
                                                                $('#Pegawai_nip').val(ui.item.nip);
                                                                $('#Jabatan_nama').val(ui.item.jabatan);
                                                                $('#Jabatan_id_jabatan').val(ui.item.id_jabatan);
                                                                }"
                                                                ),
                                                    'cssFile'=>false,
                                                    ));
                                                    echo $form->hiddenField($Pegawai, 'id_pegawai');
                                                    echo $form->error($Pegawai, 'nama');
                                                    ?>
                                            </td>
                                            <td >&nbsp;</td>
                                            <td width="150"><?php echo $form->label($Pegawai, 'nip');?></td>
                                            <td width="200">
                                                    <?php 
                                                    echo $form->textField($Pegawai, 'nip');
                                                    echo $form->error($Pegawai, 'nip');
                                                    ?>
                                            </td>
                                            <td rowspan="1" width="500">
                                            </td>
                                    </tr>
                                    <tr>
                                            <td width="150"><?php echo $form->label($Jabatan, 'Jabatan');?></td>
                                            <td width="200">
                                                    <?php 
                                                    echo $form->hiddenField($Jabatan, 'id_jabatan');
                                                    echo $form->textField($Jabatan, 'nama');
                                                    echo $form->error($Jabatan, 'nama');
                                                    ?>
                                            </td>
                                            <td colspan="3">&nbsp;</td>
                                    </tr>
                            </table>
                    </fieldset>
                </td>
                <td width="50%">
                    <fieldset>
                            <legend>Keperluan</legend>
                             <table width="50%">
                                    <tr>
                                            <td width="150"><?php echo $form->label($JenisKeperluan, 'Keperluan');?></td>
                                            <td width="200">
                                                    <?php 
                                                    $this->widget('zii.widgets.jui.CJuiAutoComplete',
                                                    array(
                                                    'model'=>$JenisKeperluan,
                                                    'attribute'=>'nama',
                                                    'source'=>$this->createUrl('JenisKeperluan/autocomplete'),
                                                    'htmlOptions'=>array('placeholder'=>'Keperluan'),
                                                    'options'=>
                                                        array(
                                                            'showAnim'=>'fold',
                                                            'select'=>"js:function(hotel, ui) {
                                                                $('#JenisKeperluan_id_keperluan').val(ui.item.id);
                                                                
                                                                }"
                                                                ),
                                                    'cssFile'=>false,
                                                    ));
                                                    echo $form->hiddenField($JenisKeperluan, 'id_keperluan');
                                                    echo $form->error($JenisKeperluan, 'nama');
                                                    ?>
                                            </td>
                                            
                                    </tr>
                                    
                            </table>
                    </fieldset>
                </td>
            </tr>
        </table>
	
	
	<?php
		echo CHtml::submitButton('Save', array('class'=>'ax-btn')); 
	$this->endWidget(); 
	?>
</div>

<?php $this->endWidget();?>
<!-- form end -->
<?php //echo $this->renderPartial('_form', array('PenerimaanTamu'=>$PenerimaanTamu)); ?>
